<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>驳回原因</title>
    <script type="text/javascript">
      var editRejectWin;
      var newRejectWin;
      var rejectId;
      Ext.onReady(function(){
        //产品分类列表------------------------------------------------------
        var rejectDS = new Ext.data.Store({
          paramNames: {
            start: "start",
            limit: "limit"
          },
          baseParams: {
            start: 0,
            limit: 15
          },
          proxy: new Ext.data.HttpProxy({
            url: '/reject/getReject'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'reson'
            }])
        });
        var rejectSM = new Ext.grid.CheckboxSelectionModel();
        var rejectCM = new Ext.grid.ColumnModel([
          new Ext.grid.RowNumberer(),rejectSM,

          {
            header: '驳回原因',
            align:"center",
            dataIndex: 'reson',
            width:580
          }]);


        var rejectGrid =  new Ext.grid.GridPanel({
          ds: rejectDS,
          cm: rejectCM,
          sm: rejectSM,
          width: screenWidth-325,
          height: screenHeight-338,
          iconCls: 'icon-grid',loadMask: true,
          tbar:[{
              text:'添加驳回原因',
              width:50,
              iconCls:'addItem',
              handler:function(){
                newRejectWin = new Ext.Window({
                  layout: 'fit',
                  width:317,
                  height:117,
                  closeAction: 'destroy',
                  plain: true,
                  modal: true,
                  constrain:true,
                  //autoScroll:true,
                  //modal: true,
                  title: '新增驳回原因',
                  autoLoad: {
                    url: "/reject/newReject",
                    scripts: true
                  }
                });
                newRejectWin.on("destroy",function(){
                  rejectDS.reload();
                });
                newRejectWin.resizable = false;
                newRejectWin.show();
              }
            },'-',{
              text: '编辑驳回原因',
              width:50,
              iconCls:'editItem',
              handler:function(){
                var records = rejectGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.alert('提示信息', '请先选中一条记录后，再编辑。');
                }else{
                  //把表单添加到窗口中
                  rejectId = records[0].get('id');
                  editRejectWin = new Ext.Window({
                    title: '编辑驳回原因',
                    layout:'fit',
                    width:317,
                    height:117,
                    closeAction:'destroy',
                    constrain:true,
                    plain: true,
                    modal: true,
                    //autoScroll:true,
                    autoLoad: {
                      url: "/reject/editReject?id=" + rejectId,
                      scripts: true
                    }
                  });
                  editRejectWin.on("destroy",function(){
                    rejectDS.reload();
                  });
                  editRejectWin.resizable = false;
                  editRejectWin.show();
                }
              }
            },'-',{
              text:'删除驳回原因',
              width:50,
              iconCls: 'remove',
              handler:function(){
                if(rejectGrid.getSelectionModel().hasSelection()){
                  var rs=rejectGrid.getSelectionModel().getSelections();
                  var ids=[];
                  var name='';
                  for(var i=0;i<rs.length;i++){
                    var data=rs[i].data;
                    ids.push(data.id);
                    name+=data.reson+'<br>';
                  }
                  var keys=Ext.util.JSON.encode(ids);
                  Ext.MessageBox.confirm('警告','确定删除以下驳回原因？<br><font color="red">' + name + '</font>',function (button){
                    if(button=='yes'){
                      Ext.Ajax.request({
                        url:'/reject/delete',
                        method:'post',
                        success:function(response,opts){
                          var data = Ext.util.JSON.decode(response.responseText);
                          if(data.success&&data.info=='success') {
                            rejectDS.reload();
                            Ext.Msg.alert('提示信息', '已成功删除。');
                          } else {
                            Ext.Msg.alert('提示信息', data.info);
                          }
                        },
                        params: {"id":keys}
                      });
                    }
                  });
                }else{
                  Ext.Msg.alert('提示信息','请选择要删除的驳回原因');
                }
              }
            }],
          bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: rejectDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })
        });
        rejectGrid.render('reject_list');
        rejectDS.load();

      })

    </script>
  </head>

  <body>
    <div id="reject_list"></div>
  </body>
</html>